package nz.ac.massey.doi_information_extractor.tests;

import static org.junit.Assert.*;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import nz.ac.massey.doi_information_extractor.data.Publication;
import nz.ac.massey.doi_information_extractor.parser.ScienceDirectExportPlugin;

import org.junit.Before;
import org.junit.Test;

//This class contains rudimentary tests for the ScienceDirectPlugin class. It's based on http://dx.doi.org/10.1016/j.websem.2006.11.007, one of Jen's papers.

public class ScienceDirectExportPluginTest {

	Publication newpub;

	@Before
	public void setUp() throws Exception{
		System.setProperty("http.proxyHost", "tur-cache.massey.ac.nz");
		System.setProperty("http.proxyPort", "8080");
		
		//This is the reason the tests take so long.
		ExecutorService pool = Executors.newFixedThreadPool(1);
		Callable<Publication> scienceDirectExportPlugin = new ScienceDirectExportPlugin("10.1016/j.websem.2006.11.007");
		Future<Publication> futureScienceDirectExportPluginResult = pool.submit(scienceDirectExportPlugin);

		newpub = futureScienceDirectExportPluginResult.get();
	}

	@Test
	public void tests() throws Exception{
		assertFalse(newpub.equals(null));
		
		assertTrue(newpub.getVolumeNumber().equals("5"));
		
		assertTrue(newpub.getEdition().equals("2"));
		
		assertTrue(newpub.getIssn().equals("1570-8268"));
		
		assertTrue(newpub.getPageNumbers().equals("108 - 116"));
		
		assertTrue(newpub.getArticleTitle().equals("Towards a web of patterns"));
		
		assertTrue(newpub.getPublicationTitle().equals("Web Semantics: Science, Services and Agents on the World Wide Web"));
		
		assertTrue(newpub.getAuthors().size() == 2 && newpub.getAuthors().get(1).getAuthorLastName().equals("Elgar"));
	}
}
